﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.7/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="lib/icheck/icheck.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>修改员工信息</title>
</head>
<body>
    <div class="page-container">
        <form class="form form-horizontal" id="form-admin-upd">
            <input type="hidden" name="S_id" id="S_id" />
            <input type="hidden" name="S_date" id="S_date" />
            <input type="hidden" name="S_state" id="S_state" />
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工姓名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="S_name" name="S_name">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>员工账号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="S_account" name="S_account">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>身份证号：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="S_IDcard" name="S_IDcard">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>初始密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="S_password" name="S_password">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>确认密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="S_password2" name="S_password2">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>性别：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="S_sex" class="radio-box" type="radio" id="S_sex1" value="男" checked>
                        <label for="sex-1">男</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="S_sex2" name="S_sex" value="女">
                        <label for="sex-2">女</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>手机：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="S_phone" name="S_phone">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>邮箱：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" placeholder="@" name="S_email" id="S_email">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">角色：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" name="s_roleID" id="s_roleID" size="1">
                            <!--<option value="0">超级管理员</option>
                            <option value="1">部门领导</option>
                            <option value="2">员工</option>-->
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">部门：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width:150px;">
                        <select class="select" name="s_Departmentid" id="s_Departmentid" size="1"></select>
                    </span>
                </div>
            </div>
            <!--<div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">备注：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea name="" cols="" rows="" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true" onkeyup="textarealength(this,100)"></textarea>
                    <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
                </div>
            </div>-->
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </div>

    <!--基本js脚本-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
    <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--扩展js脚本-->
    <script type="text/javascript" src="static/WebApi.js"></script>

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">




        //页面加载
        $(function () {

            //加载角色下拉框
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Role/Select",
                data: { "": null},
                async:false,
                success: function (data) {
                    var option = Array();
                    $(data).each(function () {
                        option.push('<option value="' + this.t_rid + '">' + this.t_rname + '</option>');
                    });
                    $("#s_roleID").append(option.join());
                },
                error: function () {
                    parent.layer.msg("ajax加载下拉框时报错！", { icon: 2, time: 1000 });
                }
            });

            //加载部门下拉框
            $.ajax({
                type: "post",
                url: ApiUrl + "api/Department/Select",
                data: { "": null },
                async:false,
                success: function (data) {
                    var option = Array();
                    $(data).each(function () {
                        option.push('<option value="' + this.t_did + '">' + this.t_dname + '</option>');
                    });
                    $("#s_Departmentid").append(option.join());
                },
                error: function () {
                    parent.layer.msg("ajax加载下拉框时报错！", { icon: 2, time: 1000 });
                }
            });

            getUpdById()//根据页面传的id获取要修改的员工信息
            

            //表单提交验证--添加功能
            $("#form-admin-upd").validate({
                rules: {
                    S_name: {
                        required: true,
                    },
                    S_password: {
                        required: true,
                    },
                    S_password2:{
                        equalTo: "#S_password",
                    },
                    S_account: {
                        required: true,
                    },
                    S_sex: {
                        required: true,
                    },
                    S_phone: {
                        required: true,
                    },
                    s_Departmentid: {
                        required: true,
                    },
                    s_roleID: {
                        required: true,
                    },
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function () {
                    $.ajax({
                        url: ApiUrl + 'api/Staff/Update',
                        type: 'post',
                        data: $("#form-admin-upd").serialize(),
                        success: function (data) {
                            if (data == true){
                                parent.layer.msg("修改员工成功！", { icon: 1, time: 2000 });
                                //var index = parent.layer.getFrameIndex(window.name);
                                //parent.$('.btn-refresh').click();
                                //parent.layer.close(index);
                                parent.location.href = 'usermanagement.html';
                            }
                            else {
                                parent.layer.msg("修改员工失败！", { icon: 2, time: 1000 });
                            }
                        },
                        error: function () {
                            parent.layer.msg("ajax加载员工信息时报错！", { icon: 2, time: 1000 });
                        }
                    });
                }
            });
        });


        //根据页面传的id获取要修改的员工信息
        function getUpdById() {
            var uri = document.documentURI;
            var i = uri.lastIndexOf("?") + 1;
            var id = uri.substr(i);

            $.ajax(
                {
                    url: ApiUrl + 'api/Staff/UpdateByid',
                    type: 'post',
                    data: { "": id },
                    async: false,
                    success: function (data) {
                        if (data != null) {

                           //  $("#form-admin-upd").val(data);--有没有直接给整个表单赋值的办法，一个个做太费劲了。
                            $("#S_id").val(data.S_id);
                            $("#S_name").val(data.S_name);
                            $("#S_phone").val(data.S_phone);
                            data.S_sex == "男" ? $("#S_sex1").attr("checked", "checked") : $("#S_sex2").attr("checked", "checked");
                            $("#S_account").val(data.S_account);
                            $("#S_password").val(data.S_password);
                            $("#S_password2").val(data.S_password);
                            $("#S_email").val(data.S_email);
                            $("#S_IDcard").val(data.S_IDcard);
                            $("#s_Departmentid").val(data.s_Departmentid);
                            $("#s_roleID").val(data.s_roleID);
                            $("#S_date").val(data.S_date);
                            $("#S_state").val(data.S_state);
                        }
                        else {
                            layer.msg("修改取值为空！", { icon: 2, time: 2000 });
                        }
                    },
                    error: function () {
                        layer.msg("ajax错误！", { icon: 2, time: 2000 });
                    }
                });
        };


    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
